#include "Square.h"
#include "Border.h"
#include "BorderChecker.h"
#include "PrecisionConvertor.h"
#include "AreaCalculator.h"
#include "PerimeterCalculator.h"

namespace
{
const unsigned int precision = 2;
}

Square::Square(double length)
    : border_m(PrecisionConvertor::getResult(length, precision, false), 
               BorderChecker(0, false, 75, false))
{
    return;
}

double Square::getArea() const
{
    double value = AreaCalculator::getResult(border_m, border_m);
    return PrecisionConvertor::getResult(value, precision, true);
}

double Square::getPerimeter() const
{
    double value = PerimeterCalculator::getResult(border_m, border_m);
    return PrecisionConvertor::getResult(value, precision, true);
}

void Square::setBorder(double length)
{
    double tempValue = border_m.getLength();
    border_m.setLength(length);
    if (!border_m.isValid()) border_m.setLength(tempValue);
}

bool Square::isValid() const
{
    return border_m.isValid();
}


